package com.lazy.book.common.enums;


import com.lazy.book.common.exception.BusinessExceptionCustomAssert;

/**
 *
 * @author lazy
 * @since 2025-09-05
 */
public interface ResponseEnumTemplate<E extends Enum<E> & ResponseEnumTemplate<E>> extends BusinessExceptionCustomAssert {

  class CustomMessageWrapper<T extends Enum<T> & ResponseEnumTemplate<T>> implements BusinessExceptionCustomAssert {

    private final T original;

    private final int customCode;

    private final String customMessage;

    public CustomMessageWrapper(T original, int customCode, String customMessage) {
      this.original = original;
      this.customCode = customCode;
      this.customMessage = customMessage;
    }

    @Override
    public int getCode() {
      return this.customCode;
    }

    @Override
    public String getMessage() {
      return this.customMessage;
    }

    @Override
    public ErrorPrefixEnum getCodePrefixEnum() {
      return original.getCodePrefixEnum();
    }
  }

  @SuppressWarnings("unchecked")
  default BusinessExceptionCustomAssert message(int code, String message) {
    return new CustomMessageWrapper<>((E) this, code, message);
  }

  default BusinessExceptionCustomAssert message(String message) {
    return message(getCode(), message);
  }
}

